<?php 
class ArrowCtrlAjax extends ArrowTagContainer{
	
	public function configure(){
		$this->registerJs( get_class($this), dirname(__FILE__)."/ArrowCtrlAjax.js", "" );
	}
	
	
	
	public function generateBlockStart(){
		return '<div class="'.self::CTRL_NAMESPACE.'-ajax '.self::CTRL_NAMESPACE.'-ajax-'.$this->getId().'">'; 
	}
	
	public function generate(){
		$children = $this->getChildren();
		$str = "";
		if(isset($children[0]))
			$str = $children[0]->generate(); 
		return $this->generateBlockStart().$str.$this->generateBlockEnd();
	}
	
	public function generateBlockEnd(){
		$str = "";
		$children = $this->getChildren();
		if( !empty($children) )
			$str.= $this->getStateCode($children[0]);
		return $str.'</div>';
	}
	
	public function getStateCode( $node ){
		$href = ArrowCtrlStateManager::getDefault()->getStateChangeLink($node, array(), true);
		return '<input type="hidden" class="'.self::CTRL_NAMESPACE.'-current-state" value="'.$href.'" />';
	}
	
	public static function generateAjaxStatements($ajaxNodeId, $node){
		$statements = array();
		$statements["start"] = '<div class="'.self::CTRL_NAMESPACE.'-ajax '.self::CTRL_NAMESPACE.'-ajax-'.$ajaxNodeId.'">';
		$href = ArrowCtrlStateManager::getDefault()->getStateChangeLink($node, array(), true);
		$statements["state"] = '<input type="hidden" class="'.self::CTRL_NAMESPACE.'-current-state" value="'.$href.'" />';
		$statements["end"] = '</div>';
		return $statements;
	}
	
}

?>